<style type="text/css">
	legend {
		font-size:8px;
		font-weight:bold;
		text-transform:uppercase;
		background:#f1f1f1;
		border-top:1px dotted #333;
		border-left:1px dotted #333;
		border-right:1px dotted #333;
		padding:3px;
		background:#ddd;
	}
	fieldset {
		background:#f4f4f4;
		border:1px dotted #333;
                margin-top: 10px;
	}
	.noborder {
		border:none;
		background:none;
	}
	input[type=button] {
		font-size:11px;
	}
</style>
<script type="text/javascript">
    function checkAllRole(className,modulSelect){
        var val=$(modulSelect).next('input').val();
        if(val==1){
            $('.'+className).attr('checked','checked');
            $(modulSelect).next('input').val('0');
            $(modulSelect).parent('td').children('font').html('Uncheck');
        }else{
            $('.'+className).removeAttr('checked');
            $(modulSelect).next('input').val('1');
            $(modulSelect).parent('td').children('font').html('Check All');
        }
    }
</script>
<div class="judul"><?php echo anchor($linkBack, $title);?> >> <?php echo "$titlePage";?></div>
<?php
  $flashdata = $this->session->flashdata('message');
  $messages = isset ($flashdata)?pesan($flashdata):"";
  echo "$messages";
  
  foreach ($dataInput as $row);
  $akses = explode("-", $row['hak_sub']);
?>
<fieldset>
    <legend>User</legend>
    <table width="100%" cellpadding="3px">
        <tr>
            <td width="150px">Nama</td><td><?php echo $row['nama'];?></td>
        </tr>
        <tr>
            <td>Username</td><td><?php echo $row['username'];?></td>
        </tr>
    </table>
</fieldset>
<fieldset>
    <legend><?php echo "$formTitle";?></legend>
    <?php
      echo form_open($subLink, '');
    ?>
    <div class="data-list">
        <table class="tabel">
            <tr>
                <th>No</th>
                <th>Module</th>
                <th>Sub Module</th>
                <th>Grant</th>
            </tr>
               <?php
                $no = 1;
                $numb = 0;
                $classModule = array();
                foreach ($listModule as $key => $module){
                   if($module['module']->id != 1){
                   $module_ = "module_$row[id]_".$module['module']->id."";
                   $classModule = $module_;
               ?>
                    <tr class="<?php echo ($no%2)?"even":"odd";?>">
                        <td style="width: 5%;text-align: center"><?php echo $no++;?></td>
                        <td><?php echo $module['module']->nama;?></td>
                        <td></td>
                        <td align="center" style="width:20%">
                            <font class="font_<?php echo "$module_";?>">Check All</font><br />
                            <?php
                              echo form_checkbox('', '', FALSE, 'onclick="checkAllRole(\''.$module_.'\',this)"');
                              echo '<input class="val_'.$module_.'" type="hidden" value="1">';
                            ?>
                        </td>
                    </tr>
                    <?php
                       $num = 1;
                       if(count($module['subModule']>0)){
                       foreach ($module['subModule'] as $sub){
                       $numb++;    
                    ?>
                    <tr class="<?php echo ($num%2)?"even":"odd";?>">
                        <td></td>
                        <td></td>
                        <td><?php echo $sub->nama;?></td>
                        <td align="center">
                           <?php
                             $cek = in_array($sub->id,$akses);
                             if($cek){
                                 $checked[$numb] = TRUE;
                             }else FALSE;
                             
                             echo form_checkbox("hak[".$sub->id."]", $sub->id, $checked[$numb], "class=".$classModule."");
                           ?> 
                        </td>
                    </tr>  
                  <?php
                      $num++; 
                      }
                      }
                    }
                 }
                 ?>
        </table>
    </div>
    <div class="input-process">
        <?php
          echo form_hidden('idUser', $row['id']);
          echo form_submit("add", "Simpan", "class='button' style='margin-right:2px'");
          echo form_button('Batal', 'Batal', 'class=button onClick='."javascript:location.href='".base_url()."index.php/user/edit_privilege/".$row['id']."'");
        ?>
    </div>
    <?php
      echo form_close();
    ?>
</fieldset>
